package org.thread.test04.demo10.homework.demo02;

import java.util.Random;

/**
 * @author CSY
 * @date 2025 - 03 - 11
 */
public class MyThread extends Thread{
    private String name;
    /**
     * 总票数
     */
    private Integer ticketCount;

    public MyThread(){}

    public MyThread(String name, Integer ticketCount) {
        this.name = name;
        this.ticketCount = ticketCount;
    }

    @Override
    public void run() {
        while(true){
            Integer sellCount = new Random().nextInt(1,10);
            if(this.ticketCount ==0){
                System.out.println(this.name+"没票了，停止售票");
                break;
            }
            if(this.ticketCount >= sellCount){
                this.ticketCount -= sellCount;
                System.out.println(this.name+"成功出售"+sellCount+"张票，剩余："+this.ticketCount);
            }else{
                sellCount = this.ticketCount ;
            }

        }
    }
}
